package com.liuzy.family.controller;

import java.io.IOException;
import java.util.Arrays;

import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.liuzy.family.config.Wx;
import com.liuzy.family.util.Decript;

/**
 * @author liuzy 2016年2月22日上午9:42:39
 */
@Controller
public class WxController {
	@RequestMapping("/wx")
	public void wx(String signature, String timestamp, String nonce, String echostr, HttpServletResponse response) throws IOException {
		String[] str = { Wx.token, timestamp, nonce };
		Arrays.sort(str);
		String temp = str[0] + str[1] + str[2];
		if (signature != null && signature.equals(Decript.SHA1(temp))) {
			response.getWriter().print(echostr);
		} else {
			response.getWriter().print("error");
		}
	}
}
